<?php
class v1_bank{
    function index(){
    	$data['basic']=$this->yum->config['Manage']['domain'].'?c=bank&a=index';
		$params=array('limit'=>array(intval($this->yum->get('start')),15));
		if($this->yum->get('locked',true)){
			$temp=$this->yum->get('locked',true);
			if(is_array($temp)){
				foreach($temp as $key=>$value){
					$data['locked'][$value]=intval($value);
					$data['basic'].='&locked[]='.$value;
				}
				$params['where']=array('A.locked IN'=>$data['locked']);
			}
		}
		if($this->yum->get('search',true)){
			$data['search']=urldecode($this->yum->get('search',true));$data['tab']=$this->yum->get('tab',true);
			if($data['search']!=''){
				if($data['tab']=='account'){
					$params['where']['A.account LIKE']='%'.$data['search'].'%';
				}else if($data['tab']=='mail'){
					$params['where']['B.mail LIKE']='%'.$data['search'].'%';
				}else if($data['tab']=='name'){
					$params['where']['A.name LIKE']='%'.$data['search'].'%';
				}
				$data['basic'].='&tab='.$data['tab'];
				$data['basic'].='&search='.urlencode($data['search']);
			}
		}
    	$bank=$this->yum->model('bank');
    	$temp=$params;$temp['select']='COUNT(*) AS count';unset($temp['limit']);
    	$data['total']=$bank->GBankFull($temp);
    	$data['total']=empty($data['total'])?0:$data['total'][0]['count'];
		$data['bank']=$bank->GBankFull($params);
		$Corr=array();
		foreach($data['bank'] as $key=>$value){
			$Corr[$value['company']]=$value['company'];
			$Corr[$value['province']]=$value['province'];
			$Corr[$value['city']]=$value['city'];
		}
		if(empty($Corr)){
			$data['sort']=array();
		}else{
			$sort=$this->yum->model('sort');
			$data['sort']=$sort->GSort(array('where'=>array('id IN'=>$Corr)));
		}
		$pagination=$this->yum->library('pagination',array('query_string'=>'start','base_url'=>$data['basic'],'total_rows'=>$data['total'],'per_page'=>15,'first_link'=>'首页','last_link'=>'末页','cur_tag_open'=>'<a href="#" class="active">','cur_tag_close'=>'</a>'));
		$data['pagination']=$pagination->create_links();
		$this->yum->set($data);
		$this->yum->view('index.php');
    }
    function locked(){
		$output=array('result'=>0,'msg'=>'');
		$bank=$this->yum->model('bank');
		$locked=intval($this->yum->get('locked',true));
		$id=$this->yum->get('member');
		if(is_array($id)){
			$affected=$bank->UBank(array('where'=>array('member IN'=>$id),'set'=>array('locked='=>$locked)));
			if($affected==0){
				$output['msg']='重复的数据提交.';
			}else{
				$output['result']=2;
			}
		}elseif(is_numeric($id)){
			$affected=$bank->UBank(array('where'=>array('member='=>$id),'set'=>array('locked='=>$locked)));
			if($affected==1){
				$output['result']=5;
				$output['td']=array('offset'=>8,'data'=>array($locked==0?'可用':'无效'));
				$output['exec']=array('attr'=>array('mixed'=>'sub:{locked:'.($locked==0?2:0).'}'),'text'=>($locked==0?'无效':'可用'));
			}else{
				$output['msg']='重复的数据提交.';
			}
		}
		header('Content-Type:text/plain');
		echo json_encode($output);
    }
    function remark(){
    	$bank=$this->yum->model('bank');
		if($this->yum->post('save')){
			$output=array('result'=>0,'msg'=>'');
			$id=intval($this->yum->post('member',true));$remark=$this->yum->post('remark',true);
			$affected=$bank->UBank(array('where'=>array('member='=>$id),'set'=>array('remark='=>$remark)));
			if($affected==1){
				$output['result']=1;
				$output['msg']='修改成功.';
			}else{
				$output['msg']='请误提交相同或未经修改的数据.';
			}
			header('Content-type:application/json');
			echo json_encode($output);
		}else{
			$data['bank']=$bank->GBank(array('where'=>array('member ='=>intval($this->yum->get('member',true)))));
			$data['bank']=reset($data['bank']);
			$this->yum->set($data);
			$this->yum->view('remark.php');
		}
    }
}
?>